package com.gistone.commis.api.restController;

import com.gistone.commis.dto.EditorResult;
import com.gistone.commis.dto.FieldError;
import com.gistone.commis.dto.Option;
import com.gistone.commis.dto.Options;
import com.gistone.commis.entity.*;
import com.gistone.commis.mapper.CommunityMapper;
import com.gistone.commis.mapper.DepartMapper;
import com.gistone.commis.mapper.LoginLogMapper;
import com.gistone.commis.util.AuditState;
import com.gistone.commis.util.DataTablePageUtil;
import com.gistone.commis.util.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by wangfan on 2017/5/20.
 */
@RestController("apiLoginLogController")
@RequestMapping("api/loginLog")
public class LoginLogController {

	private static final Logger logger = LoggerFactory.getLogger(LoginLogController.class);


	@Autowired
	private LoginLogMapper loginLogMapper;







	/**
	 * dataTables 表单数据返回
	 *
	 * @param request
	 * @return
	 */

	@Transactional
	@RequestMapping(method = RequestMethod.GET, value = "/pageDatatables")
	public DataTablePageUtil<LoginLog>  pageDatatables(HttpServletRequest request, LoginLog loginLog) {
//		HttpSession httpSession = request.getSession();
//		User user = (User) httpSession.getAttribute("userInfo");
//		logger.info("用户信息：" + user.toString());
//		int community_id = user.getCommunity().getCommunityId();
//		loginLog.setCommunityId(community_id);



		DataTablePageUtil<LoginLog> dataTable = new DataTablePageUtil<>(request);

		PageHelper.startPage(dataTable.getPage_num(), 10);
		List<LoginLog> list = loginLogMapper.selectSelective(loginLog);
		PageInfo<LoginLog> pageInfo =new PageInfo<>(list);
		System.out.println(list.size());
		dataTable.setDraw(dataTable.getDraw());
		dataTable.setData(pageInfo.getList());
		dataTable.setRecordsTotal((int)pageInfo.getTotal());
		dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
		//返回数据到页面

		return dataTable;

	}









}
